dojo.provide("uws.drawing.Component");

dojo.declare('uws.drawing.Component',null,{
	/*
		The super class of all components
	*/
	
	//from the data store
	id:null,
	diagram_id:null,
	sortOrder:null,
	
	//visual representation
	group:null,							//the actual shape + connectors + resize handles
	actual_shape_group:null,			//the actual shape
	connectors_shape_group:null,
	resize_shape_group:null,
	surface:null,
	shape_moveable:null,
	label_shape:null,
	label_shape2:null,
	label_shape3:null,
	
	//connector handles
	top_con:null,
	bottom_con:null,
	right_con:null,
	left_con:null,
	
	//resize handles
	tr_res:null,
	tl_res:null,
	br_res:null,
	bl_res:null,
	
	//group bounding box
	boundingBox:null,
	
	//for destroying the class
	s_uws_comp_index:null,
	onMoveStopHandle:null,
	focusHandle:null,
	
	constructor: function(surface,id){
		this.surface=surface;
		this.group = surface.createGroup();
		this.connectors_shape_group = this.group.createGroup();
		this.resize_shape_group = this.group.createGroup();
		this.actual_shape_group = this.group.createGroup();
		this.id = id;
		this.diagram_id = surface.id;
		this.group.owningUWSComp = this;
	},
	_postCreate:function(dx,dy){
		try{
			this.group.getNode().style.cursor="move";
		}catch(e){};
		
		this.group.applyTransform({dx:(dx-this.center_x),dy:(dy-this.center_y)});
		this.shape_moveable = new dojox.gfx.Moveable(this.group);
		this.focusHandle = this.group.connect("onclick", this, function(e){
			componentFocusManager.focus(this);
		});
		
		this.s_uws_comp_index = this.surface.uws_components.length;
		this.surface.uws_components[this.surface.uws_components.length]=this;
		this.onMoveStopHandle = dojo.connect(this.shape_moveable, "onMoveStop", null, shapeMoveHandler);
	},
	destroy:function(){
		this.shape_moveable.destroy();
		this.group.removeShape();
		this.group.disconnect(this.focusHandler);
		dojo.disconnect(this.onMoveStopHandle);
		delete(this.surface.uws_components[this.id]);
	}
});